<template>
  <div>
    <h1>订单管理</h1>
    <el-form ref="form" :model="form" class="form">
      <el-form-item>
        <el-select v-model="form.region" placeholder="按商品id查询" class="inp">
          <el-option label="按订单号查询" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input placeholder="订单号" v-model="form.id"></el-input>
      </el-form-item>
      <el-button type="primary" class="btn" @click="search">查询</el-button>
    </el-form>
    <el-table :data="list" stripe style="width: 100%">
      <el-table-column prop="" label="订单号">
        <template slot-scope="scope">
          <span style="color:#338dcc;" @click="examine(scope.row.orderNo)">{{
            scope.row.orderNo
          }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="receiverName" label="收件名"> </el-table-column>
      <el-table-column prop="statusDesc" label="订单状态"> </el-table-column>
      <el-table-column prop="payment" label="订单总价">
        <template slot-scope="scope"> ￥{{ scope.row.payment }} </template>
      </el-table-column>
      <el-table-column prop="createTime" label="注册时间"> </el-table-column>
      <el-table-column label="操作">
        <template scope="scope">
          <div>
            <span class="sp" @click="examine(scope.row.orderNo)">查看</span>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <myPagination :total="total" @pageChange="change" />
  </div>
</template>

<script>
import myPagination from "@/components/pagination";
import { order, orderSearch } from "@/utils/api";
export default {
  name: "",
  components: {
    myPagination
  },
  data() {
    return {
      form: {
        name: "",
        region: "",
        id: ""
      },
      list: [],
      total: 0
    };
  },
  mounted() {
    order(1).then(res => {
      // console.log(res);
      this.list = res.data.data.list;
      this.total = res.data.data.total;
    });
  },
  methods: {
    change(val) {
      order(val).then(res => {
        this.list = res.data.data.list;
      });
    },
    examine(id) {
      this.$router.push({ path: "/orderdetail", query: { id: id } });
    },
    search() {
      orderSearch(this.form.id).then(res => {
        if (res.data.status == 1) {
          alert("订单不存在");
        } else {
          this.list = res.data.data.list;
          this.total=res.data.data.list.length;
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.sp {
  display: inline-block;
  width: 40%;
  color: #338dcc;
}
.form {
  display: flex;
}
.inp {
  width: 160px;
  margin-right: 20px;
}
.btn {
  width: 100px;
  height: 40px;
  margin-left: 10px;
}
</style>
